package com.etoak.config;

import com.etoak.common.core.properties.ImageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

@Service
public class WebFluxConfig implements WebFluxConfigurer {

    @Autowired
    ImageProperties imageProperties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //mapping: /pics/
        String mapping=imageProperties.getMapping().endsWith("/")?
                imageProperties.getMapping()+"**":
                imageProperties.getMapping()+"/**";

        //file:======/
        String location = imageProperties.getUploadDir().endsWith("/")?
                imageProperties.getUploadDir()
                :imageProperties.getUploadDir()+"/";
        registry.addResourceHandler(mapping).addResourceLocations("file:"+location);
    }
}
